﻿using BLL;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication.Admin.api
{
    public partial class User : BaseApiPro<Models.User>
    {
        protected override BaseServicePro<Models.User> GetService()
        {
            return new BLL.User.UserService();
        }

        protected override string ListOrderBy()
        {
            return "CreatedAt Desc";
        }

        public override void List()
        {
            int totalCount = 0;


            int page = Convert.ToInt32(Request.Form["page"]);
            int limit = Convert.ToInt32(Request.Form["limit"]);
            string searchParams = Request.Form["searchParams"];


            List<Models.User> list = GetService().GetList(searchParams, ref totalCount, page, limit);

            string orderby = ListOrderBy();
            if (!string.IsNullOrEmpty(orderby))
            {
                list = GetService().GetList(searchParams, orderby, ref totalCount, page, limit);
            }

            Response.Write(JsonConvert.SerializeObject(new
            {
                code = 0,
                count = totalCount,
                msg = "",
                data = list
            }));

        }
    }
}